package com.qkst.website.backstage.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.qkst.website.backstage.bean.CategoryBean;
import com.qkst.website.backstage.bean.CategoryRelAttrBean;
import com.qkst.website.backstage.mapper.CategoryMapper;
import com.qkst.website.backstage.mapper.CategoryRelAttrMapper;
import com.qkst.website.backstage.service.CategoryService;
/**
 * @author lh
 * @description 产品类别service 业务处理层
 * @date 2017-05-03
 * @email ahlxlihao@163.com
 *
 */
@Service("categoryService")
@Transactional
public class CategoryServiceImpl implements CategoryService {
	@Resource(name = "categoryMapper")
	private CategoryMapper categoryMapper;
	@Autowired
	private CategoryRelAttrMapper categoryRelAttrMapper;

	/**
	 * 获取分类
	 * @param category
	 * @return List<CategoryBean>
	 */
	
	@Override
	public List<CategoryBean> list(CategoryBean category) {
		return categoryMapper.selectCategorys(category);
	}
	
	/**
	 * 查询总记录数
	 * @param category
	 * @return int
	 */
	@Override
	public int queryCount(CategoryBean category) {
		return categoryMapper.selectCount(category);
	}
	
	/**
	 * 保存分类
	 * @param category
	 * @return CategoryBean
	 */
	@Override
	public CategoryBean save(CategoryBean category) {
		categoryMapper.insert(category);
		return category;
	}
	
	/**
	 * 删除分类
	 * @param category
	 * @return boolean
	 */
	@Override
	public boolean delete(CategoryBean category) {
		int num=categoryMapper.deleteByPrimaryKey(category.getCategoryId());
		if(num>0){
			return true;
		}
		return false;
	}
	
	/**
	 * 保存分类与属性关系
	 * @param categoryRelAttr
	 * @return boolean
	 */
	@Override
	public boolean saveCategoryRelAttr(CategoryRelAttrBean categoryRelAttr) {
		int num=categoryRelAttrMapper.insert(categoryRelAttr);
		if(num>0){
			return true;
		}
		return false;
	}
	
}
